package cn.com.dycc.util;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import cn.com.dycc.party_org.organize.entity.PartyInfo;
/**
 * 党组织显示树 默认选中节点
 * @author linfa
 *
 */
public class PartyCheckTreeUtil {
	
	
	public static Map<String,Object> mapArray = new LinkedHashMap<String, Object>();
	public List<PartyInfo> PartyInfoCommon; 
	public List<Object> list = new ArrayList<Object>(); 
	
	//树状排序
	public List<Object> PartyList(List<PartyInfo> listPartyInfo,String[] listDeptId){ 
		this.PartyInfoCommon = listPartyInfo;
		for(PartyInfo x : listPartyInfo){
			Map<String,Object> mapArr = new LinkedHashMap<String, Object>();
			if("0".equals(x.getPid())){
				mapArr.put("id",x.getDept_id());
				mapArr.put("name",x.getDept_name());
				mapArr.put("pId",x.getPid());
//				mapArr.put("pid",x.getPid());
				mapArr.put("open","true");	
				//默认选中
//				int j = 1;
				for(String party_id : listDeptId){
					if(party_id.equals(x.getDept_id())){
						mapArr.put("checked","true");
					}
				}
				//子部门
				mapArr.put("children",children(x.getDept_id(),listDeptId));
				list.add(mapArr);
			}
		}
		return list;
	}
	
	//传入登录人的党组织父id
	public List<Object> PartyCheckListByPid(List<PartyInfo> listPartyInfo,String party_dept_pid,String[] listDeptId){ 
		this.PartyInfoCommon = listPartyInfo;
		for(PartyInfo x : listPartyInfo){
			Map<String,Object> mapArr = new LinkedHashMap<String, Object>();
			if(party_dept_pid.equals(x.getDept_id())){
				mapArr.put("id",x.getDept_id());
				mapArr.put("name",x.getDept_name());
				mapArr.put("pId",x.getPid());
//				mapArr.put("pid",x.getPid());
				mapArr.put("open","true");	
				for(String party_id : listDeptId){
					if(party_id.equals(x.getDept_id())){
						mapArr.put("checked","true");
					}
				}
				//子部门
				mapArr.put("children",children(x.getDept_id(),listDeptId));
				list.add(mapArr);
			}
		}
		return list;
	}
	
	
	
	 public List<?> children(String deptNo,String[] listDeptId){
		 List<Object> lists = new ArrayList<Object>();
		 for(PartyInfo a:PartyInfoCommon){
			 Map<String,Object> childArray = new LinkedHashMap<String, Object>();
			 if(deptNo.equals(a.getPid())){
				 childArray.put("id",a.getDept_id());
				 childArray.put("name",a.getDept_name());
				 childArray.put("pId",a.getPid());
//				 childArray.put("pid",a.getPid());
				 childArray.put("open","true");
				 //默认选中
//				 int y = 1;
				 for(String party_id : listDeptId){
					 if(party_id.equals(a.getDept_id())){
						 childArray.put("checked","true");
					 }
				 }
				 //子部门
				 childArray.put("children",children(a.getDept_id(),listDeptId)); 
				 lists.add(childArray);
			 }
		 }
		 return lists;
	 }
	 
	 
	
}
